import java.util.HashSet;
import java.util.Set;

public class GemAndStone {
    public static int numJewelsInStones(String jewels, String stones) {
        // 将宝石类型存入 HashSet，以便快速查找
        Set<Character> jewelSet = new HashSet<>();
        for (char c : jewels.toCharArray()) {
            jewelSet.add(c);
        }

        int count = 0;
        // 遍历石头并统计属于宝石的数量
        for (char c : stones.toCharArray()) {
            if (jewelSet.contains(c)) {
                count++;
            }
        }

        return count;
    }

    public static void main(String[] args) {
        // 测试用例
        String jewels = "aA";
        String stones = "aAAbbbb";
        System.out.println(numJewelsInStones(jewels, stones)); // 输出: 3

        jewels = "z";
        stones = "ZZ";
        System.out.println(numJewelsInStones(jewels, stones)); // 输出: 0
    }
}